package com.ebelter.bodyfatscale;


import com.ebelter.bodyfatscale.common.Constants;
import com.ebelter.bodyfatscale.moudules.db.beans.HistoryMesureData;
import com.ebelter.bodyfatscale.moudules.https.NetUtils;
import com.ebelter.bodyfatscale.moudules.https.interfaces.HttpResponse;
import com.ebelter.bodyfatscale.moudules.https.response.HttpsParameters;
import com.ebelter.bodyfatscale.moudules.https.response.OriginalParametersResponse;
import com.ebelter.bodyfatscale.util.UserSpUtil;
import com.ebelter.btlibrary.util.ULog;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class AddData2Ser {

    public static final String TAG = "AddData2Ser";

    public static void addData(){
        ULog.i(TAG,"addData：");
        if (!NetUtils.available()){
            return;
        }
        final long userId= UserSpUtil.readLong(Constants.IUser.USER_ID);
        if (userId<=0){
            return;
        }
        HistoryMesureData historyMesureData = new HistoryMesureData();
        historyMesureData.measureTime = "2018-12-28 18:06:22";
        historyMesureData.weight = 69.3f;
        historyMesureData.fat = 22.1f;
        historyMesureData.bmi=28.3f;
        historyMesureData.bmr=1679;
        historyMesureData.visceralFat=8;
        historyMesureData.muscleVolume=50;
        historyMesureData.boneVolume=2.4f;
        historyMesureData.protein=20;
        historyMesureData.waterRate=54f;
        historyMesureData.skeletalMuscle=27.8f;
        historyMesureData.bodyScore=57;
        historyMesureData.bodyAge=40;




        Map<String,Serializable> paramMap=new HashMap<>();
        paramMap.put(HttpsParameters.USER_ID, userId);
        paramMap.put(HttpsParameters.WEIGHT, historyMesureData.weight);
        paramMap.put(HttpsParameters.BMI, historyMesureData.bmi);
        paramMap.put(HttpsParameters.BMR, historyMesureData.bmr);
        paramMap.put(HttpsParameters.ADIPOSE_RATE, historyMesureData.fat);//脂肪率
        paramMap.put(HttpsParameters.VISCERAL_FAT, historyMesureData.visceralFat);//内脂等级
        paramMap.put(HttpsParameters.MUSCLEQUANTITY, historyMesureData.muscleVolume);
        paramMap.put(HttpsParameters.BONEMASS, historyMesureData.boneVolume);
        paramMap.put(HttpsParameters.PROTEIN, historyMesureData.protein);
        paramMap.put(HttpsParameters.MOISTURE, historyMesureData.waterRate);//水分
        paramMap.put(HttpsParameters.BONEMINERALCONTENT, historyMesureData.skeletalMuscle);//骨骼肌
        paramMap.put(HttpsParameters.BODY_SOCRE, historyMesureData.bodyScore);
        paramMap.put(HttpsParameters.PHYSICA_AGE, historyMesureData.bodyAge);
        paramMap.put(HttpsParameters.TEST_DATE, historyMesureData.measureTime);
        ULog.i(TAG,"准备上传数据库保存的数据："+historyMesureData.toString());

        NetUtils.getInstance().uploadData(TAG, paramMap, new HttpResponse<OriginalParametersResponse>() {
            @Override
            public void result(boolean isRequestSuccess, String requestDes, OriginalParametersResponse originalParametersResponse) {

                if (isRequestSuccess){
                    if (originalParametersResponse.resultCode==0){
                        ULog.i(TAG,"--上传测量1数据----上传成功---");

                    }else {
                        ULog.i(TAG,"--上传测量1数据----上传失败："+originalParametersResponse.resultMessage);
                    }
                }else {
                    ULog.i(TAG,"--上传测量1数据----网络失败");
                }

            }
        });





    }
}
